package com.my_musc_service.config;

import org.quartz.simpl.SimpleThreadPool;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Zhu Dunfeng
 * @date 2022/5/27 18:19
 */
@Configuration
public class ThreadPoolConfig {


    /**
     * 仓壁设计
     * @return
     */
    @Bean
    public SimpleThreadPool simpleThreadPool(){
        return new SimpleThreadPool(10,Thread.NORM_PRIORITY);
    }

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(10,
                20,
                5,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }

}
